import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.atomic.AtomicReference;
import java.util.function.UnaryOperator;

public class JavaMain {
    public static void main(String[] args) {
        List<Crow> list = new ArrayList<>();
        TestBirds<Crow> testBirds = new TestBirds<>();
        Crow crow = new Crow("乌鸦");
        list.add(crow);
        List<Birds> birdsList = new ArrayList<>();
        AtomicReference<Birds> data=new AtomicReference<>();
        data.updateAndGet(new UnaryOperator<Birds>() {
            @Override
            public Birds apply(Birds birds) {
                return null;
            }
        });
/**
 * 这里 birds 地方会编译报红线
 */
// testBirds.actionBirds3(birds,list);
        testBirds.actionBirds4(birdsList,list);
    }

    public static abstract class Birds {
        private String name;

        public Birds(String name) {
            this.name = name;
        }

        public void setName(String name) {
            this.name = name;
        }

        public void flight() {
            System.out.println("我是"+name+"能飞");
        }
    }

    public static class Crow extends Birds {
        public Crow(String name) {
            super(name);
        }
    }

    public static class TestBirds<T extends Birds> {
        public void actionBirds(List<T> birds) {
            for (T bird : birds) {
                bird.flight();
            }
        }

        public void actionBirds2(List<? extends T> birds) {
            for (T bird : birds) {
                birds.remove(bird);
                bird.setName("aaaaa");
                bird.flight();
            }
        }

        public void actionBirds3(List<T> birds, List<T> crows) {
            for (T crow : crows) {
                birds.add(crow);
            }
        }

        public void actionBirds4(List<? super T> birds, List<T> crows) {
            for (T crow : crows) {
                birds.add(crow);
            }
        }
    }
}